package com.wiwf.model.task.service.impl;

import com.wiwf.model.task.service.TaskOutHandlerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 任务处理服务
 *
 * @author kehui
 */
@Service
public class TaskOutHandlerServiceImpl implements TaskOutHandlerService {
    private final Logger logger = LoggerFactory.getLogger(TaskOutHandlerServiceImpl.class);

    private boolean isBroken = false;

    @Override
    public void parse(String id, String msg) {
        String stFail = "fail";
        String stMiss = "miss";
        //过滤消息
        if (msg.contains(stFail)) {
            logger.info("{}：发生故障: {}\n\t",id,msg);
            isBroken = true;
        } else if(msg.contains(stMiss)) {
            logger.info("{}：任务可能发生丢包: {}\n\t",id,msg);
            isBroken = true;
        } else {
            isBroken = false;
            logger.info("{}：{}",id,msg);
        }
    }

    @Override
    public Boolean isBroken() {
        return isBroken;
    }

}
